package com.yango.cmsservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yango.cmsservice.entity.Banner;
import com.yango.cmsservice.service.BannerService;
import com.yango.commonutil.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>首页banner表 前端控制器
 *
 * </p>
 *
 * @author LiDingYin
 * @since 2021-07-29
 */
@Api(description = "首页banner表 前端控制器")
@RestController
@RequestMapping("/cmsservice/front/banner")
public class BannerFrontController {

    @Autowired
    private BannerService bannerService;

    //查询所有banner数据
    @Cacheable(value = "banner",key = "'selectIndexList'")
    @ApiOperation(value = "查询所有banner数据")
    @GetMapping("/getBannerList")
    public Result getBannerList() {
        QueryWrapper<Banner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        wrapper.last("limit 5");
        List<Banner> bannerList = bannerService.list(wrapper);
        //返回
        return Result.ok().data("bannerList", bannerList);
    }

}

